using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BulletObject : MonoBehaviour
{
    public float moveSpeed;
    public TankBase fatherObject;
    public GameObject effectObj;

    // Update is called once per frame
    void Update()
    {
        transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
    }
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Cube" || other.tag == "Wall" || other.tag == "Player" && fatherObject.tag == "Enemy" || other.tag == "Enemy" && fatherObject.tag == "Player")
        {
            BulletHit();
        }
    }
    public void SetFather(TankBase obj)
    {
        fatherObject = obj;
    }
    public void BulletHit()
    {
        if (effectObj != null)
        {
            //创建爆炸特效
            GameObject efobj = Instantiate(effectObj, transform.position, transform.rotation);
            //设置音效
            AudioSource audios = efobj.GetComponent<AudioSource>();
            audios.volume = GameDataMgr.Instance.soundData.soundEffectValue;
            //不开启音效声音则静音
            audios.mute = !GameDataMgr.Instance.soundData.isOnSoundEffect;
        }
        Destroy(this.gameObject);
    }
}
